package day4;

import org.junit.Test;

public class OOPDemo {
    //4、类是对象的模板，对象是类的具体实例。
    //5、一个类可以创建多个对象：同一个类的不同对象，结构相同，数据不同。
    @Test
    public void test1() {
        int num = 8;
        int[] array = new int[3];

        // student1:变量，对象
        Student student1 = new Student();
        // 对象.属性
        student1.id = 1;
        student1.name = "zhangsan";
        student1.age = 23;
        student1.gender = "男";
        student1.study();

        Student student2 = new Student();
        student2.id = 2;
        student2.name = "李四";
        student2.age = 24;
        student2.gender = "女";
        student2.study();
    }

    @Test
    public void test2() {
        /*Teacher teacher1 = new Teacher();
        teacher1.id = 1;
        teacher1.name = "张老师";
        teacher1.age = 24;
        teacher1.salary = 10000;
        String info = teacher1.printInfo();
        System.out.println(info);


        Teacher teacher2 = new Teacher();
        teacher2.id = 2;
        teacher2.name = "李老师";
        teacher2.age = 34;
        teacher2.salary = 12000;
        System.out.println(teacher2.printInfo());*/

        Teacher teacher3 = new Teacher();
        teacher3.setId(3);
        teacher3.setName("张老师");
        teacher3.setAge(23);
        teacher3.setSalary(1000);
        System.out.println(teacher3);
        System.out.println(teacher3.toString());
    }

    @Test
    public void test4() {
        // 在方法里面定义的都是局部变量
        int num = 0;
        // Variable 'num' might not have been initialize
        System.out.println(num);

        Teacher teacher = new Teacher();
        System.out.println(teacher);

        Student student = new Student();
        System.out.println(student.id);// 0
        System.out.println(student.success);//false
        System.out.println(student.name);// null
        System.out.println(student.array);// null
        System.out.println(student.teachers);// null
        System.out.println(student.teacher);// null

        int[] array1 = new int[3]; //里面的存放默认值是0
        boolean[] array2 = new boolean[3]; //里面的存放默认值是false
        Student[] array3 = new Student[3]; //里面的存放默认值是null
        System.out.println("-------------");
        for (int i = 0; i < array3.length; i++) {
            System.out.println(array3[i]);
        }
    }

    @Test
    public void test3() {
        Student student = null;
        // 对象的值是null，打印是不会报错的
        System.out.println(student);// null
        // null.属性 或者  null.方法
        // java.lang.NullPointerException
        student.name = "lisi";
    }
}
